# from selenium.webdriver.support.wait import WebDriverWait
#
# from selenium import webdriver
# dr=webdriver.Chrome()
# dr.find_element_by_xpath('//input[@id="u"]').send_keys('15888888888')
# WebDriverWait(dr,10).until(lambda x: x.find)


# import subprocess, time
#
# sp = subprocess.Popen('calc.exe')
# time.sleep(3)
# sp.kill()

import csv,sys,time
with open('test.csv','r') as f:  # 读取csv文件
    file = csv.DictReader(f)
    data = [dict(i) for i in f]

# data = [{'编号(no)':'test_1','标题(title)':'打开网页','包（package）':'selenium','模块（.py）':'webdriver','类(class)':'Chrome',
#          '方法(method)':'get','步骤参数(args)':'url=http://www.woniuxy.com','预期结果(expect)':'有登录按钮','实际结果':''}]
for i in data:
    try:
        module_str = i['包（package）']+'.'+i['模块（.py）']
        __import__(module_str)  # 导模块
        m = sys.modules[module_str]  # 取模块
        cls = getattr(m,i['类(class)'])()  # 取类并实例化
        method = getattr(cls,i['方法(method)'])  # 取方法
        d = i['步骤参数(args)'].split('\n')  # 拆分换行
        kwargs = {}
        for j in d:
            k,v = j.split('=')  # 拆分=
            kwargs[k] = v
        method(**kwargs)  # 调用方法
        time.sleep(1)
        a = cls.find_element_by_link_text('注销').text  # 获取元素文本
        if a in i['预期结果(expect)']:  # 判断
            i['实际结果'] = '通过'
        else:
            i['实际结果'] = '不通过'
        print(i)
    except Exception as e:
        print(e)




